#!/bin/bash

echo "=== Akka + RocketMQ 微服务启动脚本 ==="

# 检查Docker是否运行
if ! docker info > /dev/null 2>&1; then
    echo "错误: Docker未运行，请先启动Docker"
    exit 1
fi

# 启动RocketMQ
echo "1. 启动RocketMQ服务..."
docker-compose up -d

# 等待RocketMQ启动
echo "2. 等待RocketMQ服务启动..."
sleep 30

# 检查RocketMQ状态
echo "3. 检查RocketMQ服务状态..."
docker-compose ps

# 启动订单服务
echo "4. 启动订单服务..."
cd order-service
mvn spring-boot:run &
ORDER_PID=$!

# 等待订单服务启动
sleep 10

# 启动库存服务
echo "5. 启动库存服务..."
cd ../inventory-service
mvn spring-boot:run &
INVENTORY_PID=$!

echo "6. 服务启动完成！"
echo "订单服务 PID: $ORDER_PID"
echo "库存服务 PID: $INVENTORY_PID"
echo ""
echo "服务地址:"
echo "- 订单服务: http://localhost:8080"
echo "- 库存服务: http://localhost:8081"
echo "- RocketMQ控制台: http://localhost:8180"
echo ""
echo "按 Ctrl+C 停止所有服务"

# 等待用户中断
trap "echo '正在停止服务...'; kill $ORDER_PID $INVENTORY_PID; docker-compose down; exit" INT
wait

